<!DOCTYPE html>
<html class="x-admin-sm">
  
  <head>
    <meta charset="UTF-8">
    <title>权限添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/index.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/index.js"></script>
 
  </head>
  
  <body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form  id="authform" method="post" class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span>权限名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="auth_name" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
               
                   <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                       <span class="x-red">*</span>绑定菜单
                    </label>
                    <div class="layui-input-inline">
                        <select  id="memuid"  name="memuid" 
                        autocomplete="off" class="layui-input">
                     
                         
                        </select>
                    </div>
                </div>
               
                <div class="layui-form-item layui-form-text">
                    <label for="desc" class="layui-form-label">
                        描述
                    </label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" id="desc" name="auth_desc" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                <input type="button" value="增加" class="layui-btn"  onclick="add()">
              </div>
            </form>
        </div>
    </div>
    <script src="js/jquery.js"></script>
 
    <script>
    	
    	     selects();
    	//模糊查询
    	function selects(){   		
    		$.ajax({
    			type:"get",
    			url:"http://localhost:16111/memurbac/reachaddafter",
    			xhrFields:{withCredentials: true},
    			dataType:"json",    			    		
    			success:function(res){
    				//表示为查询成功，
    				if(res.code==200){
    		     
    			
    					   	//添加菜单列表
    		          	$('#memuid').html("");
    					for(var i in res.data.memus){
    						
    						var str="<option value=\""+res.data.memus[i].id+"\">"+res.data.memus[i].memu_name+"</option>"
    					$('#memuid').html($('#memuid').html()+str);
    					}
    					   
    					  
    					   //重新加載js文件
    					   loadJs("./lib/layui/lay/modules/form.js");
    					
    				}else{
    					
    					layui.use("layer", function () {
                //提示错误信息
    					layer.msg(res.error,{icon:7,time:1000});
             })

    					
    				
    				}
    			},
    			error:function(error){
    			
    				layui.use("layer", function (){
             	//提示错误信息
    				layer.msg(JSON.stringify(error),{icon:2,time:1000});
             })
    				
    			}
    		});
   
    	}
    	
        
          //监听提交
           function add(){ 
         
         
        //alert(JSON.stringify(data.field));
         
        
            //发异步，把数据提交给服务器
             		$.ajax({
    			type:"get",
    			url:"http://localhost:16111/memurbac/addauth",
    			xhrFields:{withCredentials: true},
    			dataType:"json",    			
    			data:$('#authform').serialize(),
    			success:function(res){
    				//表示为新增权限成功
    				if(res.code==200){
    			    	//提示成功信息
    				 		layui.use("layer", function () {
                
          
    					 layer.alert(res.data, {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                parent.selects();
                //关闭当前frame
                parent.layer.close(index);
            });
            
       });
    				}else{
    					//提示错误信息
    				layui.use("layer", function () {
    						 layer.alert(res.error, {icon: 7},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
            
         });
    					
    				}
    			},
    			error:function(error){
    				//提示错误信息
    			layui.use("layer", function () {
    								 layer.alert(error, {icon: 2},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
         });
    			}
    				
    		});
           
          }

        
        //重新加载js文件
        function loadJs(file)
{
    var head = $("head").remove("script[role='reload']");
    $("<scri"+"pt>"+"</scr"+"ipt>").attr({ 
    role:'reload',src:file,type:'text/javascript'}).appendTo(head);
}
    </script>



  </body>

</html>